
#The following syntax replicates the graphic used in Carbone, Soroka and Dunaway, 
#"The Psychophysiology of News Avoidance: Does Negative Affect Drive both Attention 
#and Inattention to News?," forthcoming in Journalism Studies. 

#Variables in the dataset NewsAvoidance.Rdata are as follows:
#resp Respondent Number
#storyF News Story (factor variable)
#period 1=pre-story gray screen, 2=story
#timesecStoryF Count of seconds within each story (factor variable)
#gslmc Galvanic Skin Levels, mean-centered by respondent

load("NewsAvoidance.Rdata")
library(effects, quietly = T) 

##pool
model4 <- lm(gslmc ~ timesecStoryF , data=a[a$storyF=="1.Pool" & a$period==2,])
eff4 <- effect("timesecStoryF", model4, typical=mean)
eff4r <- cbind(eff4$x,fit=eff4$fit,lower=eff4$lower,higher=eff4$upper)
eff4r$time <- as.numeric(rownames(eff4r))
poly <- c(eff4r$time,rev(eff4r$time))
gon <- c(eff4r$lower,rev(eff4r$higher))
polyg4 <- as.data.frame(cbind(poly,gon))

##castille
model3 <- lm(gslmc ~ timesecStoryF , data=a[a$storyF=="3.Castille" & a$period==2,])
eff3 <- effect("timesecStoryF", model3, typical=mean)
eff3r <- cbind(eff3$x,fit=eff3$fit,lower=eff3$lower,higher=eff3$upper)
eff3r$time <- as.numeric(rownames(eff3r))
poly <- c(eff3r$time,rev(eff3r$time))
gon <- c(eff3r$lower,rev(eff3r$higher))
polyg3 <- as.data.frame(cbind(poly,gon))


{
png("figure1.png",width=7,height=9,units="in",bg="white",res=300)

par(mfrow=c(2,1), mar = c(5.1, 4.1, 2.1, 2.1) )

plot(eff4r$time, eff4r$fit,  type="n", ann=F, axes=F, ylim=c(-.5,1.5))
abline(h=0,lty=2)
abline(v=10,lty=3) ; abline(v=20,lty=3) ; abline(v=30,lty=3) ; abline(v=40,lty=3) ; abline(v=50,lty=3) ; abline(v=60,lty=3) ; abline(v=70,lty=3) ; abline(v=80,lty=3) ; abline(v=90,lty=3) ; abline(v=100,lty=3) ; abline(v=110,lty=3) ; abline(v=120,lty=3) ; abline(v=130,lty=3) ; abline(v=140,lty=3); abline(v=150,lty=3) ; abline(v=160,lty=3) ; abline(v=170,lty=3) ; abline(v=180,lty=3) ; abline(v=190,lty=3) ; abline(v=200,lty=3)
polygon(polyg4$poly,polyg4$gon,border=NA,col="gray",density=36,angle=90)
lines(eff4r$time, eff4r$fit,  type="l", col="black",lwd=4)
axis(side=2, las=1, cex.axis=.8, col="black")
mtext(side=2,expression(paste("Normalized Skin Conductance")),cex=.8,line=3)
axis(side=1, las=1, cex.axis=.8, col="white", padj=.8, at=c(1,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160))
mtext(side=1,"Seconds",cex=1,line=3)
#text(1,1.45,"Pool Story",pos=4,cex=1.5)
legend(-1, 1.65, "Pool Story", box.col = "white", bg = "white", cex=1.5)

plot(eff3r$time, eff3r$fit,  type="n", ann=F, axes=F, ylim=c(-.5,1.5))
abline(h=0,lty=2)
abline(v=10,lty=3) ; abline(v=20,lty=3) ; abline(v=30,lty=3) ; abline(v=40,lty=3) ; abline(v=50,lty=3) ; abline(v=60,lty=3) ; abline(v=70,lty=3) ; abline(v=80,lty=3) ; abline(v=90,lty=3) ; abline(v=100,lty=3) ; abline(v=110,lty=3) ; abline(v=120,lty=3) ; abline(v=130,lty=3) ; abline(v=140,lty=3); abline(v=150,lty=3) ; abline(v=160,lty=3) ; abline(v=170,lty=3) ; abline(v=180,lty=3) ; abline(v=190,lty=3) ; abline(v=200,lty=3)
polygon(polyg3$poly,polyg3$gon,border=NA,col="gray",density=36,angle=90)
lines(eff3r$time, eff3r$fit,  type="l", col="black",lwd=4)
axis(side=2, las=1, cex.axis=.8, col="black")
mtext(side=2,expression(paste("Normalized Skin Conductance")),cex=.8,line=3)
axis(side=1, las=1, cex.axis=.8, col="white", padj=.8, at=c(1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160))
mtext(side=1,"Seconds",cex=1,line=3)
#text(1,1.45,"Castille Story",pos=4,cex=1.5)
legend(-1, 1.65, "Castille Story", box.col = "white", bg = "white", cex=1.5)

dev.off()
}





